package cn.com.connext.scrm.service;

import cn.com.connext.scrm.domain.master.DwaGetCategoryCount;
import cn.com.connext.scrm.domain.master.DwaQuestionRecord;
import cn.com.connext.scrm.repository.master.DwaGetCategoryCountRepository;
import cn.com.connext.scrm.repository.master.DwaQuestionRecordRepository;
import cn.com.connext.scrm.service.dto.JsonResult;
import cn.com.connext.scrm.web.rest.vm.DwaQuestionRecordVM;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.ZonedDateTime;
import java.util.List;

@Service
@Transactional
public class DwaGetCategoryCountService {
    @Autowired
    private DwaGetCategoryCountRepository dwaGetCategoryCountRepository;


    public List<DwaGetCategoryCount> findAll() {
        return dwaGetCategoryCountRepository.findAll();
    }

    public List<String> findUserCount() {
        return dwaGetCategoryCountRepository.findUserCount();
    }

    public JsonResult addMsg(DwaGetCategoryCount entity) {
        JsonResult result =new JsonResult();
        if(StringUtils.isEmpty(entity.getUnionId())){
            result.setMessage("用户unionId不能为空");
            result.setState(-1);
        }else{
            entity.setCreateTime(ZonedDateTime.now());
            dwaGetCategoryCountRepository.save(entity);
            result.setMessage("添加成功");
            result.setState(0);
        }
        return result;
    }
}
